package Test08;

//网络编程

//UDP的三种通信方式（组播发送端代码）

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class Test06 {
    public static void main(String[] args) throws IOException {

        //1、创建MulticastSocket对象
        MulticastSocket ms = new MulticastSocket();

        //2、打包数据
        String str = "你好，你好！！！";
        byte[] bytes = str.getBytes();
        InetAddress address = InetAddress.getByName("224.0.0.1");
        int port = 10000;

        DatagramPacket dp = new DatagramPacket(bytes, bytes.length, address, port);

        //3、发送数据
        ms.send(dp);

        //4、释放资源
        ms.close();

    }
}
